#!/usr/bin/env python
# -*- coding: utf-8 -*-
#测试夜神安卓模拟器，连接模拟器中的安卓系统，打开浏览器使用搜索

from appium import webdriver
from appium.webdriver.extensions import applications
from appium.webdriver.extensions.keyboard import Keyboard
from selenium.webdriver.common.keys import Keys
from appium.webdriver.extensions.android.nativekey import AndroidKey
import time

desired_caps = {
  "platformName": "Android",
  "plathformVersion": "7",
  "deviceName": "ttt",
  "app":"",
  "appPackage": "com.vphone.launcher",
  "appActivity": "com.vphone.launcher.launcher3.Launcher",
  "noReset": True,
  "newCommandTimeout": 6000
}

driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
element = driver.find_element_by_xpath("//android.widget.TextView[@content-desc=\"浏览器\"]")
element.click()
driver.wait_activity(activity="com.android.browser:id/url",timeout=20)
element = driver.find_element_by_id("com.android.browser:id/url")

element.click()
element.clear()

element.send_keys("www.baidu.com")
# driver.press_keycode(AndroidKey.ENTER)
driver.keyevent(keycode=66)
time.sleep(5)